<?php
    @header("Content-Type:text/html;charset=utf-8");

    @include_once("conn.php");  
    @include_once("common.php");

     if(!isset($_GET["pid"])){ 
        paramsErr();
    }

    //通过pid传值 查找pid
    $pid = $_GET["pid"];
    $sql = "select * from `products` where pid = '$pid'";
    $res = mysqli_query($conn,$sql);

    $obj = array();
    if($res){ // 判断查询的结果;
        
        $item = mysqli_fetch_assoc($res);
        if($item){
            // 数据库中存放大图片小图片
            $smallList = explode(",",$item["smallPicList"]);   // 将字符串拆分为数组
            $item["smallPicList"] = array_slice($smallList,0,3);  // 取前个3

            $bigList = explode(",",$item["bigPicList"]);   // 将字符串拆分为数组
            $item["bigPicList"] = array_slice($bigList,0,3);  // 取前3个

        
            $obj["status"] = true;
            $obj["msg"] = "success";
            $obj["data"] = $item;
            
        }else{
            $obj["status"] = false;
            $obj["msg"] = "该商品不存在";
            $obj["sql"] = $sql;
        }
    }else{
        $obj["status"] = false;
        $obj["msg"] = "sql语句有误";
        $obj["sql"] = $sql;
    }
    echo json_encode($obj);
?>